<?php
namespace app\common\model;

use think\Model;
use think\Db;
class PlaformPapers extends Model
{
    // 指定表名,不含前缀
    protected $name = 'plaform_papers';

 
    public function getListByArg(array $arg=null,$field='*'){
        if (!is_array($arg))return false;
        $arg = $this->where($arg)->field($field)->select();
        return $arg;
    }
	public function getListByArgOne(array $arg=null,$field='*'){
        if (!is_array($arg))return false;
        $arg = $this->where($arg)->field($field)->find();
        return $arg;
    }

	public function getListByArgAss($plaformid=0,$type=0){
		$qb_id = array();
        //$arg = Db::name('qbank_association')->where(['plaformid'=>$plaformid,'marks'=>1])->field('qb_id')->select();
		$arg =  Db::name('qbank_association')->where(['plaformid'=>$plaformid,'marks'=>1]);
		if($type==1){
			$arg = $arg->where('status=0');
		} else if($type==2){
			$arg = $arg->where('status=1');
		}
		$arg = $arg->field('qb_id')->select();

		foreach($arg as $v){
			$qb_id[] = $v['qb_id'];
		}
        return $qb_id;
    }
	
	public function getListByArgqbankid($plaformid=0){
		$qb_id = array();
        $arg = $this->where(['plaform_id'=>$plaformid])->field('qbankid')->find();
		$qbankid =$arg->qbankid;
		if(!empty($qbankid)){
			$qbankid =explode(',',str_ireplace('|','',$qbankid));
			
			foreach($qbankid as $v){
				if(!empty($v)){
					$qb_id[] = $v;
				}
			}
			
		}
        return $qb_id;
    }
	
	public function getListByArgAssSubject($plaformid=0){
		if(!$plaformid) return false;
		$qb_id = array();
		//$arg = self::getListByArgAss($plaformid,1);
		$arg = self::getListByArgAss($plaformid);
		if(empty($arg)){
			return $qb_id;
		} else {
			$subject_id = array();
			$Paper = new \app\common\model\Paper();
			$subject = $Paper->getListByArg(['id'=>['in',$arg]],'distinct p_subject');
			foreach($subject as $v){
				$subject_id[] = ['q_subjectid'=>$v->p_subject];
			}
			$admin_reg = getChildAdminRegByPlaformId($this->plaform,3);
			$Subject = new \app\common\model\Subject();
			$Subject_name = $Subject->subjectAll($subject_id);
			return $Subject_name;
		}
    }
	
}
